#include "types.h"

#ifndef _VS1053_H
#define	_VS1053_H

/*====================== SCI instructions ================= */
#define VS1053_READ		0x03
#define VS1053_WRITE		0x02

/*====================== SCI registers =====================*/
#define VS1053_SCI_MODE		0x00
    #define SM_DIFF	0x0001
    #define SM_LAYER12	0x0002
    #define SM_RESET	0x0004
    #define SM_CANCEL	0x0008
    #define SM_EARSPEAKER_LO 0x0010
    #define SM_TESTS	0x0020
    #define SM_STREAM	0x0040
    #define SM_EARSPEAKER_HI 0x0080
    #define SM_DACT	0x0100
    #define SM_SDIORD	0x0200
    #define SM_SDISHARE 0x0400
    #define SM_SDINEW	0x0800
    #define SM_ADPCM	0x1000
    #define SM_LINE1	0x4000
    #define SM_CLK_RANGE 0x8000
#define VS1053_SCI_STATUS	0x10
    #define SS_DO_NOT_JUMP 0x8000
    #define SS_SWING	0x7000
    #define SS_VCM_OVERLOAD 0x0800
    #define SS_VCM_DISABLE  0x0400
    #define SS_VER	0x00F0
    #define SS_APDOWN2	0x0008
    #define SS_APDOWN1	0x0004
    #define SS_ADCLOCK	0x0002
    #define SS_SS_REF_SEL 0x0001
#define VS1053_SCI_BASS		0x20
    #define ST_AMPLITUDE 0xF000
    #define ST_FREQLIMIT 0x0F00
    #define SB_AMPLITUDE 0x00F0
    #define SB_FREQLIMIT 0x000F
#define VS1053_SCI_CLOCKF	0x30
    #define SC_MULT_0	0x0000
    #define SC_MULT_2	0x2000
    #define SC_MULT_25	0x4000
    #define SC_MULT_3	0x6000
    #define SC_MULT_35	0x8000
    #define SC_MULT_4	0xa000
    #define SC_MULT_45	0xc000
    #define SC_MULT_5	0xe000
    #define SC_ADD	0x1800
    #define SC_FREQ	0x07FF
#define VS1053_SCI_DECODE_TIME	0x40    
#define VS1053_SCI_AUDATA	0x50
#define VS1053_SCI_WRAM		0x60
#define VS1053_SCI_WRAMADDR	0x70
#define VS1053_SCI_HDAT0	0x80
    #define HDAT0_bitrate  0xF000
    #define HDAT0_samplerate 0x0D00
    #define HDAT0_pad	   0x0200
    #define HDAT0_private  0x0100
    #define HDAT0_mode 	   0x000D0
    #define HDAT0_extension 0x0030
    #define HDAT0_copyright 0x0008
    #define HDAT0_original  0x0004
    #define HDAT0_emphasis  0x0003
#define VS1053_SCI_HDAT1	0x90
    #define HDAT1_syncword 0xFFF8
    #define HDAT1_layer	   0x0006
    #define HDAT1_protect  0x0001
#define VS1053_SCI_AIADDR	0xA0
#define VS1053_SCI_VOL		0xB0
#define VS1053_SCI_AICTRL0	0xC0
#define VS1053_SCI_AICTRL1	0xD0
#define VS1053_SCI_AICTRL2	0xE0
#define VS1053_SCI_AICTRL3	0xF0

/*=============== functions ============================*/
void VS1053_SoftReset(void);
void VS1053_Init(void);

void VS1053_SetVolume( byte vol ); /* 0x00 - max, 0xFE mute, volume level on both channels*/
byte VS1053_GetVolume( void );
void VS1053_SetBass( byte bass ); /* 0 - off , 4-MSB-> amplitude, 4-LSB->freq*/
byte VS1053_GetBass( void );
void VS1053_SetTreble( byte treble ); /* 0 - 0ff, 4-MSB-> amplitude, 4-LSB->freq */
byte VS1053_GetTreble( void );

void VS1053_Patch( void ); /*FLAC patch*/

void VS1053_Data32( byte* data );
void VS1053_Data( byte data );

void VS1053_Write( byte addr, UINT16 data );
UINT16 VS1053_Read( byte addr );

void VS1053_spi_write( byte data );
byte VS1053_spi_read( void );

#endif